package com.example.a2207_zh.fragment

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.a2207_zh.entity.LoveResult
import com.example.a2207_zh.entity.VideoEntityResult
import com.example.a2207_zh.mvvm.BaseViewModel
import com.example.a2207_zh.net.ApiServer
import kotlinx.coroutines.launch

class VideoViewModel:BaseViewModel() {

    val videoSuccess = MutableLiveData<VideoEntityResult>()
    val videoFail = MutableLiveData<String>()

    fun video(currentPage:Int,pageSize:Int){
        viewModelScope.launch {
            try {
                videoSuccess.value = apiServer.video(currentPage, pageSize)
            }catch (e:Exception){
                videoFail.value = e.message
            }
        }
    }

    val loveSuccess = MutableLiveData<LoveResult>()
    val loveFail = MutableLiveData<String>()
    fun love(videoId:Int){
        viewModelScope.launch {
            try {
                loveSuccess.value = apiServer.love(videoId)
            }catch (e:Exception){
                loveFail.value = e.message
            }
        }
    }

    val noloveSuccess = MutableLiveData<LoveResult>()
    val noloveFail = MutableLiveData<String>()
    fun nolove(videoId:Int){
        viewModelScope.launch {
            try {
                noloveSuccess.value = apiServer.nolove(videoId)
            }catch (e:Exception){
                noloveFail.value = e.message
            }
        }
    }


}